/**
 * 前端枚举常量定义
 * 与后端枚举保持同步
 * 
 * @author Wu.Liang
 * @since 2025-01-29
 */

/**
 * 角色代码枚举
 */
export const ROLE_CODE = {
  /** 超级管理员 */
  SUPER_ADMIN: 'SUPER_ADMIN',
  /** 系统管理员 */
  ADMIN: 'ADMIN',
  /** 区域管理员 */
  REGION_ADMIN: 'REGION_ADMIN',
  /** 社区管理员 */
  COMMUNITY_ADMIN: 'COMMUNITY_ADMIN',
  /** 物业管理员 */
  PROPERTY_ADMIN: 'PROPERTY_ADMIN',
  /** 物业员工 */
  PROPERTY_STAFF: 'PROPERTY_STAFF',
  /** 安保人员 */
  SECURITY_STAFF: 'SECURITY_STAFF',
  /** 安保管理 */
  SECURITY_ADMIN: 'SECURITY_ADMIN',
  /** 保洁人员 */
  CLEANING_STAFF: 'CLEANING_STAFF',
  /** 保洁管理 */
  CLEANING_ADMIN: 'CLEANING_ADMIN',
  /** 停车人员 */
  PARKING_STAFF: 'PARKING_STAFF',
  /** 停车管理 */
  PARKING_ADMIN: 'PARKING_ADMIN',
  /** 维修人员 */
  REPAIR_STAFF: 'REPAIR_STAFF',
  /** 楼栋管理员 */
  BUILDING_ADMIN: 'BUILDING_ADMIN',
  /** 单元管理员 */
  UNIT_ADMIN: 'UNIT_ADMIN',
  /** 房户管理员 */
  HOUSEHOLD_ADMIN: 'HOUSEHOLD_ADMIN',
  /** 业主 */
  OWNER: 'OWNER',
  /** 普通用户/居民 */
  NORMAL_USER: 'NORMAL_USER',
  /** 居民 */
  RESIDENT: 'RESIDENT'
} as const

/**
 * 角色代码与描述映射
 */
export const ROLE_CODE_DESC = {
  [ROLE_CODE.SUPER_ADMIN]: '超级管理员',
  [ROLE_CODE.ADMIN]: '管理员',
  [ROLE_CODE.REGION_ADMIN]: '区域管理员',
  [ROLE_CODE.COMMUNITY_ADMIN]: '社区管理员',
  [ROLE_CODE.PROPERTY_ADMIN]: '物业管理员',
  [ROLE_CODE.PROPERTY_STAFF]: '物业人员',
  [ROLE_CODE.SECURITY_STAFF]: '安保人员',
  [ROLE_CODE.SECURITY_ADMIN]: '安保管理',
  [ROLE_CODE.CLEANING_STAFF]: '保洁人员',
  [ROLE_CODE.CLEANING_ADMIN]: '保洁管理',
  [ROLE_CODE.PARKING_STAFF]: '停车人员',
  [ROLE_CODE.PARKING_ADMIN]: '停车管理',
  [ROLE_CODE.REPAIR_STAFF]: '维修人员',
  [ROLE_CODE.BUILDING_ADMIN]: '楼栋管理员',
  [ROLE_CODE.UNIT_ADMIN]: '单元管理员',
  [ROLE_CODE.HOUSEHOLD_ADMIN]: '房户管理员',
  [ROLE_CODE.OWNER]: '业主',
  [ROLE_CODE.NORMAL_USER]: '普通用户',
  [ROLE_CODE.RESIDENT]: '居民'
} as const

/**
 * 角色选项列表
 */
export const ROLE_OPTIONS = Object.entries(ROLE_CODE_DESC).map(([code, desc]) => ({
  label: desc,
  value: code
}))

/**
 * 系统状态枚举
 */
export const STATUS = {
  /** 禁用/停用 */
  DISABLED: 0,
  /** 启用/正常 */
  ENABLED: 1,
  /** 锁定/冻结 */
  LOCKED: 2
} as const

/**
 * 审核状态枚举
 */
export const AUDIT_STATUS = {
  /** 待审核 */
  PENDING: 0,
  /** 审核通过 */
  APPROVED: 1,
  /** 审核拒绝 */
  REJECTED: 2
} as const

/**
 * 状态与描述映射
 */
export const STATUS_DESC = {
  [STATUS.DISABLED]: '禁用',
  [STATUS.ENABLED]: '启用',
  [STATUS.LOCKED]: '锁定'
} as const

/**
 * 审核状态与描述映射
 */
export const AUDIT_STATUS_DESC = {
  [AUDIT_STATUS.PENDING]: '待审核',
  [AUDIT_STATUS.APPROVED]: '审核通过',
  [AUDIT_STATUS.REJECTED]: '审核拒绝'
} as const

/**
 * 状态选项列表
 */
export const STATUS_OPTIONS = Object.entries(STATUS_DESC).map(([code, desc]) => ({
  label: desc,
  value: Number(code)
}))

/**
 * 审核状态选项列表
 */
export const AUDIT_STATUS_OPTIONS = Object.entries(AUDIT_STATUS_DESC).map(([code, desc]) => ({
  label: desc,
  value: Number(code)
}))

/**
 * 基础状态选项（启用/禁用）
 */
export const BASIC_STATUS_OPTIONS = [
  { label: '禁用', value: STATUS.DISABLED },
  { label: '启用', value: STATUS.ENABLED }
]

/**
 * 用户类型枚举
 */
export const USER_TYPE = {
  /** 居民 */
  RESIDENT: 1,
  /** 物业人员 */
  PROPERTY_STAFF: 2,
  /** 管理员 */
  ADMIN: 3,
  /** 安保人员 */
  SECURITY_GUARD: 4,
  /** 维修人员 */
  MAINTENANCE_STAFF: 5
} as const

/**
 * 用户类型与描述映射
 */
export const USER_TYPE_DESC = {
  [USER_TYPE.RESIDENT]: '居民',
  [USER_TYPE.PROPERTY_STAFF]: '物业人员',
  [USER_TYPE.ADMIN]: '管理员',
  [USER_TYPE.SECURITY_GUARD]: '安保人员',
  [USER_TYPE.MAINTENANCE_STAFF]: '维修人员'
} as const

/**
 * 用户类型选项列表
 */
export const USER_TYPE_OPTIONS = Object.entries(USER_TYPE_DESC).map(([code, desc]) => ({
  label: desc,
  value: Number(code)
}))

/**
 * 支付状态枚举
 */
export const PAYMENT_STATUS = {
  /** 待支付 */
  PENDING: 0,
  /** 已支付 */
  PAID: 1,
  /** 支付成功 */
  SUCCESS: 2,
  /** 支付失败 */
  FAILED: 3,
  /** 已取消 */
  CANCELLED: 4,
  /** 已退款 */
  REFUNDED: 5,
  /** 部分退款 */
  PARTIAL_REFUNDED: 6
} as const

/**
 * 支付状态与描述映射
 */
export const PAYMENT_STATUS_DESC = {
  [PAYMENT_STATUS.PENDING]: '待支付',
  [PAYMENT_STATUS.PAID]: '已支付',
  [PAYMENT_STATUS.SUCCESS]: '支付成功',
  [PAYMENT_STATUS.FAILED]: '支付失败',
  [PAYMENT_STATUS.CANCELLED]: '已取消',
  [PAYMENT_STATUS.REFUNDED]: '已退款',
  [PAYMENT_STATUS.PARTIAL_REFUNDED]: '部分退款'
} as const

/**
 * 支付状态选项列表
 */
export const PAYMENT_STATUS_OPTIONS = Object.entries(PAYMENT_STATUS_DESC).map(([code, desc]) => ({
  label: desc,
  value: Number(code)
}))

/**
 * 删除标记枚举
 */
export const DELETED = {
  /** 未删除 */
  NOT_DELETED: 0,
  /** 已删除 */
  DELETED: 1
} as const

/**
 * 删除标记与描述映射
 */
export const DELETED_DESC = {
  [DELETED.NOT_DELETED]: '未删除',
  [DELETED.DELETED]: '已删除'
} as const

/**
 * 工具函数
 */

/**
 * 检查是否为超级管理员角色
 */
export function isSuperAdminRole(roleCode: string): boolean {
  return roleCode === ROLE_CODE.SUPER_ADMIN || roleCode === ROLE_CODE.ADMIN
}

/**
 * 检查是否为管理员角色
 */
export function isAdminRole(roleCode: string): boolean {
  return [
    ROLE_CODE.SUPER_ADMIN,
    ROLE_CODE.ADMIN,
    ROLE_CODE.REGION_ADMIN,
    ROLE_CODE.COMMUNITY_ADMIN,
    ROLE_CODE.PROPERTY_ADMIN,
    ROLE_CODE.BUILDING_ADMIN,
    ROLE_CODE.UNIT_ADMIN,
    ROLE_CODE.HOUSEHOLD_ADMIN,
    ROLE_CODE.SECURITY_ADMIN,
    ROLE_CODE.CLEANING_ADMIN,
    ROLE_CODE.PARKING_ADMIN
  ].includes(roleCode as any)
}

/**
 * 检查是否为物业相关角色
 */
export function isPropertyRole(roleCode: string): boolean {
  return [
    ROLE_CODE.PROPERTY_ADMIN,
    ROLE_CODE.PROPERTY_STAFF,
    ROLE_CODE.BUILDING_ADMIN,
    ROLE_CODE.UNIT_ADMIN,
    ROLE_CODE.HOUSEHOLD_ADMIN
  ].includes(roleCode as any)
}

/**
 * 检查是否为工作人员角色
 */
export function isStaffRole(roleCode: string): boolean {
  return [
    ROLE_CODE.PROPERTY_STAFF,
    ROLE_CODE.SECURITY_STAFF,
    ROLE_CODE.REPAIR_STAFF,
    ROLE_CODE.CLEANING_STAFF,
    ROLE_CODE.PARKING_STAFF
  ].includes(roleCode as any)
}

/**
 * 检查是否为安保相关角色
 */
export function isSecurityRole(roleCode: string): boolean {
  return [
    ROLE_CODE.SECURITY_ADMIN,
    ROLE_CODE.SECURITY_STAFF
  ].includes(roleCode as any)
}

/**
 * 检查是否为保洁相关角色
 */
export function isCleaningRole(roleCode: string): boolean {
  return [
    ROLE_CODE.CLEANING_ADMIN,
    ROLE_CODE.CLEANING_STAFF
  ].includes(roleCode as any)
}

/**
 * 检查是否为停车相关角色
 */
export function isParkingRole(roleCode: string): boolean {
  return [
    ROLE_CODE.PARKING_ADMIN,
    ROLE_CODE.PARKING_STAFF
  ].includes(roleCode as any)
}

/**
 * 检查是否为居民角色
 */
export function isResidentRole(roleCode: string): boolean {
  return [
    ROLE_CODE.RESIDENT,
    ROLE_CODE.NORMAL_USER,
    ROLE_CODE.OWNER
  ].includes(roleCode as any)
}

/**
 * 检查是否为启用状态
 */
export function isEnabled(status: number): boolean {
  return status === STATUS.ENABLED
}

/**
 * 检查是否为禁用状态
 */
export function isDisabled(status: number): boolean {
  return status === STATUS.DISABLED
}

/**
 * 检查是否为已支付状态
 */
export function isPaid(paymentStatus: number): boolean {
  return paymentStatus === PAYMENT_STATUS.PAID || paymentStatus === PAYMENT_STATUS.SUCCESS
}

/**
 * 检查是否为未支付状态
 */
export function isUnpaid(paymentStatus: number): boolean {
  return paymentStatus === PAYMENT_STATUS.PENDING
}

/**
 * 根据状态获取状态描述
 */
export function getStatusDesc(status: number): string {
  return STATUS_DESC[status as keyof typeof STATUS_DESC] || '未知状态'
}

/**
 * 根据用户类型获取描述
 */
export function getUserTypeDesc(userType: number): string {
  return USER_TYPE_DESC[userType as keyof typeof USER_TYPE_DESC] || '未知类型'
}

/**
 * 根据角色代码获取描述
 */
export function getRoleDesc(roleCode: string): string {
  return ROLE_CODE_DESC[roleCode as keyof typeof ROLE_CODE_DESC] || '未知角色'
}

/**
 * 根据支付状态获取描述
 */
export function getPaymentStatusDesc(paymentStatus: number): string {
  return PAYMENT_STATUS_DESC[paymentStatus as keyof typeof PAYMENT_STATUS_DESC] || '未知状态'
} 